import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:lottie/lottie.dart';
import '../controllers/contract_controller.dart';
import '../widgets/sign_in_rewards.dart';
import '../widgets/contracts_list.dart';
import '../widgets/sorting_popup.dart';

class ContractPage extends StatefulWidget {
  const ContractPage({super.key});

  @override
  State<ContractPage> createState() => _ContractPageState();
}

class _ContractPageState extends State<ContractPage>
    with TickerProviderStateMixin {
  final contractController = Get.put(ContractController());

  @override
  void initState() {
    super.initState();
    contractController.animationController = AnimationController(
      duration: const Duration(seconds: 10),
      vsync: this,
    );
    contractController.animationController.addStatusListener((status) {
      if (status == AnimationStatus.completed) {
        contractController.showAnimation.value = false;
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
        gradient: LinearGradient(
          begin: Alignment.topCenter,
          end: Alignment.bottomCenter,
          colors: [
            const Color(0xFF0A0E27),
            const Color(0xFF1A1F3A),
            const Color(0xFF0A0E27),
          ],
        ),
      ),
      child: Stack(
        children: [
          Image.asset('assets/images/pic_contract_bg.png', fit: BoxFit.cover),
          // 主内容
          SingleChildScrollView(
            child: Column(
              children: [
                SizedBox(height: 50.h),
                // GestureDetector(
                //   onTap: () {
                //     print('测试');
                //     contractController.initializeCheckIn();
                //   },
                //   child: Container(
                //     width: 100.w,
                //     height: 100.h,
                //     color: Colors.red,
                //     child: Text('测试'),
                //   ),
                // ),
                // 签到奖励组件
                const SignInRewards(),

                // VIP合约列表
                const ContractsListWidget(),

                SizedBox(height: 20.h),
              ],
            ),
          ),

          // 排序弹窗
          const SortingPopup(),
          Obx(() {
            return contractController.showAnimation.value
                ? Lottie.asset(
                  'assets/anim/congratulation/data.json',
                  width: 1.sw,
                  fit: BoxFit.cover,
                  controller: contractController.animationController,
                )
                : SizedBox.shrink();
          }),
        ],
      ),
    );
  }
}
